# 服务入口

from flask import Flask, request
import json
from run_pb import main
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

# 裂缝检测
@app.route('/checkDetection', methods=['GET'])
def checkDetection():
    file = request.args.get('file')
    inputs = './web/www/crack/uploads/' + file
    outputs = './web/www/crack/result/' + file
    main(None, inputs, outputs)
    data = {'file': outputs}
    json_data = json.dumps(data)
    return json_data

@app.route('/process_string', methods=['POST'])
def process_string():
    data = request.get_json()  # 获取POST请求的JSON数据
    dynamic_string = data.get('string', '')  # 从JSON数据中获取字符串
    # 在这里处理你的动态字符串
    processed_string = dynamic_string + ' 已经被处理过。'

    return {'processed_string': processed_string}  # 返回处理过的字符串

if __name__ == '__main__':
    app.run(host='127.0.0.1', port=5000)